﻿// LOGIN_DIA.cpp: 实现文件
//

#include "stdafx.h"
#include "MFCApplication4.h"
#include "LOGIN_DIA.h"
#include "afxdialogex.h"
#include"BankSystem.h"
#include<string>
#include"MFCApplication4Dlg.h"
// LOGIN_DIA 对话框

IMPLEMENT_DYNAMIC(LOGIN_DIA, CDialogEx)

LOGIN_DIA::LOGIN_DIA(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_LOGIN, pParent)
{
	
}

LOGIN_DIA::~LOGIN_DIA()
{
}

void LOGIN_DIA::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, ID_LOGIN, LoginButton);
	DDX_Control(pDX, IDC_EDIT1, UsernameText);
	DDX_Control(pDX, IDC_EDIT2, PasswordText);
}


BEGIN_MESSAGE_MAP(LOGIN_DIA, CDialogEx)
	ON_BN_CLICKED(ID_LOGIN, &LOGIN_DIA::OnBnClickedLogin)
	ON_BN_CLICKED(ID_QUIT, &LOGIN_DIA::OnBnClickedQuit)
	ON_BN_CLICKED(IDC_REGISTER, &LOGIN_DIA::OnBnClickedRegister)
END_MESSAGE_MAP()


// LOGIN_DIA 消息处理程序


void LOGIN_DIA::OnBnClickedLogin()
{
	int check = 0;
	std::string username;
	std::string password;
	CString up;
	CString pp;
	GetDlgItemText(IDC_EDIT1, up);
	GetDlgItemText(IDC_EDIT2, pp);
	username = CT2A(up.GetString()); 
	password = CT2A(pp.GetString());
	if (username == "")
	{
		::MessageBox(NULL, _T("请输入用户名"), _T("提示"), MB_ICONWARNING);
		check = 1;
	}
	else if (password == "")
	{
		::MessageBox(NULL, _T("请输入密码"), _T("提示"), MB_ICONWARNING);
		check = 1;
	}
	if (check==0)
	{
	int i=SystemALL.Login(username, password);
	switch (i)
	{
	case 1:
		::MessageBox(NULL, _T("您的密码输入有误！"), _T("提示"), MB_ICONWARNING); break;
	case -1:
		::MessageBox(NULL, _T("您的用户名输入有误！"), _T("提示"), MB_ICONWARNING); break;
	case 0:
		::MessageBox(NULL, _T("登陆成功"), _T("提示"), MB_OK);
		SystemALL.usernow = username;
		CMFCApplication4Dlg *Main=new CMFCApplication4Dlg;
		Main->DoModal();
		break;
	}
	}
}


void LOGIN_DIA::OnBnClickedQuit()
{
	// TODO: 在此添加控件通知处理程序代码
	exit(0);
}


void LOGIN_DIA::OnBnClickedRegister()
{
	int check = 0;
	std::string username;
	std::string password;
	CString up;
	CString pp;
	GetDlgItemText(IDC_EDIT1, up);
	GetDlgItemText(IDC_EDIT2, pp);
	username = CT2A(up.GetString());
	password = CT2A(pp.GetString());
	if (username == "")
	{
		::MessageBox(NULL, _T("请输入用户名"), _T("提示"), MB_ICONWARNING);
		check = 1;
	}
	else if (password == "")
	{
		::MessageBox(NULL, _T("请输入密码"), _T("提示"), MB_ICONWARNING);
		check = 1;
	}
	if (check == 0)
	{
		int i = SystemALL.SignUp(username, password);
		if (username == "")
			::MessageBox(NULL, _T("请输入用户名"), _T("提示"), MB_ICONWARNING);
		else if (password == "")
			::MessageBox(NULL, _T("请输入密码"), _T("提示"), MB_ICONWARNING);
		switch (i)
		{
		case 0:
			::MessageBox(NULL, _T("注册成功！"), _T("提示"), MB_OK); 
			BankSystem::Beginer(SystemALL);
			break;
		case -1:
			::MessageBox(NULL, _T("您键入的用户名已被注册！"), _T("提示"), MB_ICONWARNING); break;
		}
	}
	// TODO: 在此添加控件通知处理程序代码
}
